<?php
include('config.php');
//$where = 1;
$type_name = isset($_POST['type_name']) ? $_POST['type_name'] : '';
$name = isset($_POST['name_name']) ? $_POST['name_name'] : '';
if($type_name){
	$type_id_rs = $mysql->selectlist("type","type_name='{$type_name}'");
	$type_id = $type_id_rs[0]['type_id'];
	$where = "n.type_id = '{$type_id}'";
}
if($type_name && $name){
	$breed_id_rs = $mysql->selectlist("breed","breed_name='{$name}'");
	$breed_id = $breed_id_rs[0]['breed_id'];
	$where = "n.breed_id = '{$breed_id}'";
}
$sql = "SELECT n.*,b.breed_name,t.type_name FROM `number` n left join breed b on n.breed_id=b.breed_id left join type t on n.type_id=t.type_id";
$sql .= " where ".$where;
$n = 0;
echo "<table id='tables'>";
echo "<tr class='type_query_top_tr'>";
echo "<td class='weight_style'>类别</td><td class='weight_style'>品种</td><td class='weight_style'>编号</td><td class='type_query_last_th'>操作</td>";
echo "</tr>";
$rs = $mysql->execute($sql);
while($row = mysql_fetch_assoc($rs)){
	$n = $n;
	$num = $n%2;
	echo "<tr class='type_query_tr{$num}'>
			<td id='type_name{$row['number_id']}'>{$row['type_name']}</td>
			<td id='breed_name{$row['number_id']}'>{$row['breed_name']}</td>
			<td id='number_name{$row['number_id']}'>{$row['number_name']}</td>
			<td class='type_query_last_td' id='edit{$row['number_id']}' ><span onclick='edit_type({$row['number_id']},{$row['type_id']},{$row['breed_id']})'>编辑</span></td>
		  </tr>";
	//echo "<tr class='type_query_tr{$num}'><td id='type_name{$row['number_id']}'>{$row['type_name']}</td><td id='breed_name{$row['number_id']}'>{$row['breed_name']}</td><td id='number_name{$row['number_id']}'>{$row['number_name']}</td><td class='type_query_last_td' id='edit{$row['number_id']}'><span onclick='edit_type({$row['number_id']},{$row['type_id']},{$row['breed_id']})'>编辑</span></td></tr>";
	$n++;
}
echo "</table>";